<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form id="reg">
        <input class="user" type="text" placeholder="请输入账号">
        <input class="pwd" type="password" placeholder="请输入密码">
        <button>立即注册</button>
        <script>
            var form = document.querySelector('#reg')
            var user = document.querySelector('.user')
            var pwd = document.querySelector('.pwd')
            form.onsubmit = function (e) {
                e.preventDefault()
                var username = user.value.trim()
                var password = pwd.value.trim()
                if (!username || !password) {
                    return alert('请输入账号或密码')
                }
                var accountList = JSON.parse(localStorage.getItem('accountList') || '[]')
                accountList.push({ username: username, password: password })
                localStorage.setItem('accountList', JSON.stringify(accountList))
                alert('注册成功')
                user.value = ''
                pwd.value = ''
            }
        </script>
    </form>
</body>

</html>